-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SymbolicHamiltonian
refactor
#1548
base: master
Are you sure you want to change the base?
Conversation
SymbolicHamiltonian
terms
and dense
settersSymbolicHamiltonian
refactor
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1548 +/- ##
==========================================
- Coverage 99.67% 99.64% -0.04%
==========================================
Files 76 76
Lines 11234 11115 -119
==========================================
- Hits 11198 11076 -122
- Misses 36 39 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I am still unsure whether it is worth keeping the two different ways for computing the dense form of the {
"2q": 36,
"3q": 81,
"4q": 144,
"5q": 225,
"6q": 324,
"7q": 441,
"8q": 576,
"9q": 729,
"10q": 900,
"11q": 1089
} the average runtimes across 10 runs are as follows: time vs nqubits time vs nterms the Long story short, if I had to pick only one of the two I'd probably lean towards the EDIT: a small update on this one: I've done some minor optimization to the at this point it is maybe not worth keeping |
I marked the PR as ready for review, but keep in mind that this
is still up. I am testing right now whether there I can fix them in qibojit directly (qiboteam/qibojit#199), otherwise I will have to distribute some casts here. @stavros11 @renatomello may I ask you guys to have a look a this if you have time, I presume you two were the main contributors to the hamiltonian module. There are still some parts of the code that I left in commented because they are up for discussion and I would like to conduct some more tests on a GPU. |
Thanks @BrunoLiegiBastonLiegi for the refactor. This part of is admittedly quite messy. I did not have a detailed look in the code (will do soon), just some quick feedback on the first comment.
Personally, I don't see this as a big issue, particularly because the old
particularly to avoid the need for such workarounds.
I don't fully remember what's that for, but based on the docstring it was planned to be removed anyway, so it should be fine.
In principle, these are also kind of "breaking" so we could even just do a breaking release with this PR. |
This should address #1494
EDIT: this turned out to be more in general a refactor of
SymbolicHamiltonian
and partly ofhamiltonian/models.py
. Namely,SymbolicHamiltonian
now only has aform
attribute,dense
andterms
are cached properties computed starting fromform
and, thus, they can no longer be manually setted. Concerninghamiltonian/models.py
, now the models are built starting from theform
and not theterms
as it was before. I also made the dense representation of the models more backend aware, replacing thenumpy
operations with the backend ones.Note: tests on
cupy
are still failing due to this qiboteam/qibojit#196 .EDIT 2:
I went ahead and provided both
Symbols
andSymbolicTerm
with abackend
attribute which is useful whenever you move to the dense form representation. Initially, I thought about makingbackend
an additional input argument to the functions that needed it (similarly to what we do with gates), but this would have meant breaking the api (e.g.symbol.matrix
->symbol.matrix(backend)
).What it means now though, is that there are cases where the backends of the different pieces may mismatch, thus causing problems. To mitigate this, I decided to forcely set the backend of the symbols here https://github.com/qiboteam/qibo/blob/4d8c9c1211c850a5e740607de943da75fc31f8b2/src/qibo/hamiltonians/terms.py#L176C1-L179C50
which allows for the end user to not care about which backend to construct a symbol with, maintaining in practice the usual API.
As part of the refactor, I removed the
symbol_map
argument of the hamiltonians, thefrom_symbolic
method and theTrotterHamiltonian
.Checklist: